import axios from 'axios'
import type {getPaperofType,getsubjectsType,getexamtype,examparams,PreviewType,getquestiontype,addcreateType,createparamsType} from './type'
import type {CreateExamRreponse,CreateExamParams} from './type'


// 试卷库创建人调取的接口
export const getPaperof = () => {
  return axios.get<getPaperofType>('/user/list?page=1&pagesize=100')
}
// 试卷库科目调取接口
export const getsubjects = () => {
  return axios.get<getsubjectsType> ('/classify/list?page=1&pagesize=100')
}

// 试卷考试历史接口
export const getexamlist =  (params:examparams) => {
  const filteredParams = Object.fromEntries(
    Object.entries(params).filter(([_, v]) => v !== '')
  );
  return axios.get<getexamtype> ('/exam/list',{
    params: filteredParams,
  })
}

// 试卷库删除接口
export const removeitem = (id:string) => {
  return axios.post<getexamtype> ('/exam/remove',{id})
}

// 预览试卷接口
export const Previewparper = (id:string) => {
  return axios.get<PreviewType>('/exam/detail',{
    params:{
      id
    },
  })
}

// 题目类型接口
export const questiontype = () => {
  return axios.get<getquestiontype>('/question/type/list')
}

// 创建试卷提交接口

export const getaddcreate = (params:addcreateType) => {
  return axios.post('exam/create',{...params})
}

//点击编辑后保存的接口

export const getupdate = (params:createparamsType) => {
  return axios.post('/exam/update',{...params})
}
// 创建考试接口
export const CreateExam = (data: CreateExamParams) => {
  return axios.post<CreateExamRreponse>('/examination/create', data, {
    headers: {
      'Content-Type': 'application/json'
    }
  })
}
// 删除考试接口
export const deleteExam = (id: string) => {
  return axios.post<CreateExamRreponse>('/examination/remove', { id })
}
